package com.yanqu.road.server.cmd.kowloon;

import com.yanqu.road.entity.kowloon.KowloonUserData;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.kowloon.KowloonProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.kowloon.KowloonModule;
import com.yanqu.road.server.pb.KowloonPb;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = Protocol.S_KOWLOON_ENTER_CHAPTER, desc = "进入关卡")
public class KowloonEnterChapterCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {

        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        KowloonProto.KowloonEnterChapterReqMsg req = KowloonProto.KowloonEnterChapterReqMsg.parseFrom(packet.getBytes());
        List<Integer> heroIdList = new ArrayList<>(req.getHeroIdList());
        ret = player.getModule(KowloonModule.class).enterChapter(req.getChapterId(), heroIdList);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            player.sendPacket(ClientProtocol.U_KOWLOON_ENTER_CHAPTER, KowloonProto.KowloonEnterChapterRespMsg.newBuilder().setRet(ret));
        }
    }
}
